package com.aspire.shiro.service.impl;

import com.aspire.shiro.service.SecurityService;
import com.aspire.shiro.tools.DigestsUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class SecurityServiceImpl implements SecurityService {
    @Override
    public Map<String, String> getPasswordByUsername(String username) {

        //返回通过密码的工具类生成的密码(模拟从数据库查的加密的密码)
        return DigestsUtil.entryPassword("admin");
    }

    @Override
    public List<String> findRoleByLoginName(String userName) {
        List<String> result = new ArrayList<>();
        if ("admin".equals(userName)) {
            result.add("admin");
        }
        result.add("develop");
        result.add("test");
        return result;
    }

    @Override
    public List<String> findPermissionByLoginName(String userName) {
        List<String> result = new ArrayList<>();
        if ("test".equals(userName)) {
            result.add("order:select");
            result.add("order:delete");
            result.add("order:update");
            result.add("order:insert");
        }
        return result;
    }
}
